package com.example.a2209_shop.fg

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.example.a2209_shop.R
import com.example.a2209_shop.adapter.ScAdapter
import com.example.a2209_shop.database.DataBaseUtils
import com.example.a2209_shop.databinding.FragmentScBinding
import com.example.base.mvvm.BaseViewFragment


class ScFragment : BaseViewFragment<FragmentScBinding>() {
    lateinit var scAdapter: ScAdapter
    override fun initData() {

    }

    override fun initView() {
        scAdapter  = ScAdapter()
        binding.rv.adapter = scAdapter
        binding.rv.layoutManager = LinearLayoutManager(context)

        //点击跳转到详情界面
        scAdapter.setOnItemClickListener {  adapter, view, position ->
            ARouter.getInstance().build("/app/deta").withInt("goods_id",scAdapter.data[position].id).navigation()
        }
    }

    override fun getLayout(): Int  = R.layout.fragment_sc

    override fun onResume() {
        super.onResume()
        val data = DataBaseUtils.getDb().getGoodsDao().queryColl()
        scAdapter.data.clear()
        scAdapter.data.addAll(data)
        scAdapter.notifyDataSetChanged()
    }

}